import { Component } from '@angular/core';

import { NavController } from 'ionic-angular';
import {MarketingDailyListPage} from "../daily/list/list.component";
import {MarketingWeeklyListPage} from "../weekly/list/list.component";
import {MarketingLineupListPage} from "../lineup/list/list.component";
import {MarketingHomePage} from "../home/home.component";
import {MarketingMobilePage} from "../mobile/mobile.component";
import {MarketingIndexService} from "./index.service";
import _ from "lodash";

@Component({
	selector: 'page-marketing-index',
	templateUrl: 'index.html',
  providers: [MarketingIndexService]
})
export class MarketingIndexPage {
	moa_page_name: any = "page-marketing-index";
  moa_page_explain: any = "营销平台";

	menu = [{
		icon: "gtjl.png",
		name: "工作日报",
		listType: "daily"
	}, {
		icon: "gzzb.png",
		name: "工作周报",
		listType: "weekly"
	}, {
		icon: "paidui.png",
		name: "任务管理",
		listType: "lineUp"
	}];
	constructor(
	    public navCtrl: NavController,
	    private indexService: MarketingIndexService
	) {
	    this.indexService.getUSBHomepageAuthority().subscribe(result => {
	        if (result["hasAuthority"]) {
	            this.menu = _.concat([{
	                icon: "yxsy.png",
	                name: "营销首页",
	                listType: "home"
	            }], this.menu);
	        }
	        if (result.hasAnalysis) {
	            this.menu.push({
	                icon: "jyfx.png",
	                name: "经营分析",
	                listType: "mobile"
	            });
	        }
	    });
	}

	openPage(item) {
		// 如果是列表，跳转到列表页面
		switch (item.listType) {
      case 'home':
        this.navCtrl.push(MarketingHomePage);
        break;
      case 'daily':
        this.navCtrl.push(MarketingDailyListPage);
        break;
      case 'weekly':
        this.navCtrl.push(MarketingWeeklyListPage);
        break;
      case 'lineUp':
        this.navCtrl.push(MarketingLineupListPage);
		break;
	  case "mobile":
		  this.navCtrl.push(MarketingMobilePage);
		  break;
    }
	}
}

